package org.poseidon.report.controller;

import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.poseidon.common.annotation.Log;
import org.poseidon.common.core.controller.BaseController;
import org.poseidon.common.core.domain.CommonResult;
import org.poseidon.common.core.page.TableDataInfo;
import org.poseidon.common.enums.BusinessType;
import org.poseidon.common.utils.poi.ExcelUtil;
import org.poseidon.report.domain.BuProject;
import org.poseidon.report.domain.vo.BuProjectAddVO;
import org.poseidon.report.domain.vo.BuProjectEditVO;
import org.poseidon.report.input.BuProjectInput;
import org.poseidon.report.service.IBuProjectService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目Controller
 * 
 * @author gfc
 * @date 2022-02-23
 */
@RestController
@RequestMapping("/report/project")
@Api(tags = "项目接口")
public class BuProjectController extends BaseController
{
    @Autowired
    private IBuProjectService buProjectService;

    /**
     * 查询项目列表
     */
    @PreAuthorize("@ss.hasPermi('report:project:list')")
    @PostMapping("/list")
    @ApiOperation(value = "查询项目列表")
    public TableDataInfo list(@RequestBody BuProjectInput input)
    {
        BuProject buProject = new BuProject();
        BeanUtils.copyProperties(input,buProject);
        PageHelper.startPage(input.getPageNum(), input.getPageSize());
        List<BuProject> list = buProjectService.selectBuProjectList(buProject);
        return getDataTable(list);
    }
    @ApiOperation(value = "新增里程碑-获取项目列表")
    @GetMapping("/getProjectList")
    public TableDataInfo getProjectList(){
       List<BuProject> list=  buProjectService.getProjectList();
       return  getDataTable(list);
    }
    /**
     * 导出项目列表
     */
    @PreAuthorize("@ss.hasPermi('report:project:export')")
    @Log(title = "项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出项目列表")
    public void export(HttpServletResponse response, BuProject buProject)
    {
        List<BuProject> list = buProjectService.selectBuProjectList(buProject);
        ExcelUtil<BuProject> util = new ExcelUtil<BuProject>(BuProject.class);
        util.exportExcel(response, list, "项目数据");
    }

    /**
     * 获取项目详细信息
     */
    @ApiOperation(value = "获取项目详细信息")
    @PreAuthorize("@ss.hasPermi('report:project:query')")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        BuProjectEditVO buProject = buProjectService.selectProjectByPrimary(id);
        return CommonResult.success(buProject);
    }

    /**
     * 新增项目
     */
    @PreAuthorize("@ss.hasPermi('report:project:add')")
    @Log(title = "项目", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value="新增项目")
    public CommonResult add(@RequestBody BuProjectAddVO buProject)
    {
        buProjectService.addProject(buProject);
        return CommonResult.success();
    }

    /**
     * 修改项目
     */
    @PreAuthorize("@ss.hasPermi('report:project:edit')")
    @Log(title = "项目", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改项目")
    public CommonResult edit(@RequestBody BuProjectEditVO editVO)
    {
        buProjectService.updateProject(editVO);
        return CommonResult.success();
    }

    /**
     * 删除项目
     */
    @PreAuthorize("@ss.hasPermi('report:project:remove')")
    @Log(title = "项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/remove")
    @ApiOperation(value ="删除项目 单选或多选")
    public CommonResult remove(@RequestBody List<Long> ids)
    {
        return toAjax(buProjectService.deleteBuProjectByIds(ids));
    }
}
